package com.wali.modules.common.bo;

import com.wali.common.ccp.execl.annotation.CcpExcelField;
import com.wali.modules.common.vo.ComGoodsVO;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author walixu
 * @ClassName com.wali.modules.common.bo
 * @Description 备案商品信息BO类
 * @email wali.xu@kpmg.com
 * @date 09/03/2019 2:14 下午
 */
public class ComGoodsBO implements Serializable {

    /**
     * 客户id
     */
    @CcpExcelField(title = "客户ID", value = "userNo")
    private String userNo;

    /**
     * 商品序列号
     */
    @CcpExcelField(title = "商品序列号", value = "serialNo")
    private String serialNo;

    /**
     * 海关商品序编号
     */
    @CcpExcelField(title = "海关商品编码", value = "customerGoodsId")
    private String customerGoodsId;

    /**
     * 品名
     */
    @CcpExcelField(title = "品名", value = "goodsName")
    private String goodsName;

    /**
     * 英文品名
     */
    @CcpExcelField(title = "英文品名", value = "goodsEnname")
    private String goodsEnname;

    /**
     * 品牌
     */
    @CcpExcelField(title = "品牌", value = "brand")
    private String brand;

    /**
     * 规格
     */
    @CcpExcelField(title = "规格", value = "specs")
    private String specs;

    /**
     * 原产国
     */
    @CcpExcelField(title = "原产国", value = "orginCountry")
    private String orginCountry;

    /**
     * 计量单位
     */
    @CcpExcelField(title = "计量单位", value = "unit")
    private String unit;

    /**
     * 商品净重kg
     */
    @CcpExcelField(title = "商品净重kg", value = "goodsWeight")
    private String goodsWeight;

    /**
     * 商品毛重kg
     */
    @CcpExcelField(title = "商品毛重kg", value = "totalWeight")
    private String totalWeight;

    /**
     * 单价/公斤
     */
    @CcpExcelField(title = "商品申报单价", value = "price")
    private String pricekg;

    /**
     * 商品单价/货物的单价
     */
    @CcpExcelField(title = "建议申报价/人民币", value = "priceCny")
    private String priceGoods;

    /**
     * 商品币制
     */
    @CcpExcelField(title = "商品币制", value = "currency")
    private String currency;

    public String getSerialNo() {
        return serialNo;
    }

    public void setSerialNo(String serialNo) {
        this.serialNo = serialNo;
    }

    public String getCustomerGoodsId() {
        return customerGoodsId;
    }

    public void setCustomerGoodsId(String customerGoodsId) {
        this.customerGoodsId = customerGoodsId;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getGoodsEnname() {
        return goodsEnname;
    }

    public void setGoodsEnname(String goodsEnname) {
        this.goodsEnname = goodsEnname;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getSpecs() {
        return specs;
    }

    public void setSpecs(String specs) {
        this.specs = specs;
    }

    public String getOrginCountry() {
        return orginCountry;
    }

    public void setOrginCountry(String orginCountry) {
        this.orginCountry = orginCountry;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public String getGoodsWeight() {
        return goodsWeight;
    }

    public String getTotalWeight() {
        return totalWeight;
    }


    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public void setGoodsWeight(String goodsWeight) {
        this.goodsWeight = goodsWeight;
    }

    public void setTotalWeight(String totalWeight) {
        this.totalWeight = totalWeight;
    }

    public String getPricekg() {
        return pricekg;
    }

    public void setPricekg(String pricekg) {
        this.pricekg = pricekg;
    }

    public String getPriceGoods() {
        return priceGoods;
    }

    public void setPriceGoods(String priceGoods) {
        this.priceGoods = priceGoods;
    }

    public String getUserNo() {
        return userNo;
    }

    public void setUserNo(String userNo) {
        this.userNo = userNo;
    }

    @Override
    public String toString() {
        return "ComGoodsBO{" +
                "userNo='" + userNo + '\'' +
                ", serialNo='" + serialNo + '\'' +
                ", customerGoodsId='" + customerGoodsId + '\'' +
                ", goodsName='" + goodsName + '\'' +
                ", goodsEnname='" + goodsEnname + '\'' +
                ", brand='" + brand + '\'' +
                ", specs='" + specs + '\'' +
                ", orginCountry='" + orginCountry + '\'' +
                ", unit='" + unit + '\'' +
                ", goodsWeight='" + goodsWeight + '\'' +
                ", totalWeight='" + totalWeight + '\'' +
                ", pricekg='" + pricekg + '\'' +
                ", priceGoods='" + priceGoods + '\'' +
                ", currency='" + currency + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ComGoodsBO that = (ComGoodsBO) o;
        return Objects.equals(userNo, that.userNo) &&
                Objects.equals(serialNo, that.serialNo) &&
                Objects.equals(customerGoodsId, that.customerGoodsId) &&
                Objects.equals(goodsName, that.goodsName) &&
                Objects.equals(goodsEnname, that.goodsEnname) &&
                Objects.equals(brand, that.brand) &&
                Objects.equals(specs, that.specs) &&
                Objects.equals(orginCountry, that.orginCountry) &&
                Objects.equals(unit, that.unit) &&
                Objects.equals(goodsWeight, that.goodsWeight) &&
                Objects.equals(totalWeight, that.totalWeight) &&
                Objects.equals(pricekg, that.pricekg) &&
                Objects.equals(priceGoods, that.priceGoods) &&
                Objects.equals(currency, that.currency);
    }

    @Override
    public int hashCode() {
        return Objects.hash(userNo, serialNo, customerGoodsId, goodsName, goodsEnname, brand, specs, orginCountry, unit, goodsWeight, totalWeight, pricekg, priceGoods, currency);
    }

    /**
     * @param comGoods
     * @return
     * @throws
     * @Title
     * @Description 转换
     */
    public static ComGoodsVO convert(ComGoodsBO comGoods) {
        ComGoodsVO temp = new ComGoodsVO();
        temp.setBrand(comGoods.getBrand());
        temp.setCurrency(comGoods.getCurrency());
        temp.setCustomerGoodsId(comGoods.getCustomerGoodsId());
        temp.setGoodsName(comGoods.getGoodsName());
        temp.setGoodsEnname(comGoods.getGoodsEnname());
        if (StringUtils.isNotBlank(comGoods.getGoodsWeight())) {
            temp.setGoodsWeight(Double.parseDouble(comGoods.getGoodsWeight()));
        } else {
            temp.setGoodsWeight(0);
        }
        temp.setOrginCountry(comGoods.getOrginCountry());
        if (StringUtils.isNotBlank(comGoods.getPricekg())) {
            if(comGoods.getPricekg().indexOf("SUM") != -1) {
                temp.setPricekg(Double.parseDouble(comGoods.getPriceGoods()) / temp.getGoodsWeight());
            } else{
                temp.setPricekg(Double.parseDouble(comGoods.getPricekg()));
            }
        } else {
            temp.setPricekg(0);
        }

        if (StringUtils.isNotBlank(comGoods.getPriceGoods())) {
            temp.setPriceGoods(Double.parseDouble(comGoods.getPriceGoods()));
        } else {
            temp.setPriceGoods(0);
        }

        temp.setSerialNo(comGoods.getSerialNo());
        if (StringUtils.isNotBlank(comGoods.getTotalWeight())) {
            temp.setTotalWeight(Double.parseDouble(comGoods.getTotalWeight()));
        } else {
            temp.setTotalWeight(0);
        }
        temp.setSpecs(comGoods.getSpecs());
        temp.setUnit(comGoods.getUnit());
        temp.setUserNo(comGoods.getUserNo());
        return temp;
    }
}
